<?php

/**
 *
 */
class order_config
{
    /**
     * 订单类型
     * =================================================
     */

    /**
     * 合伙人订单
     */
    const ORDER_TYPE_DEALER = 1;

    /**
     * 门店(终端)订单
     */
    const ORDER_TYPE_STORE = 5;


    // 合伙人订单状态, 旧流程
    public static $dealer_progress_old = array(
        '1' => '待收款(旧)',
        '3' => '等待配送(旧)',
        '5' => '配送中(旧)',
        '10' => '配送完成(旧)',
    );

    // 合伙人订单状态, 新流程
    public static $dealer_progress = array(
        '15' => '订单取消',
        '20' => '待扣款',
        '30' => '已扣款待确认',
        '40' => '已确认待打印',

        // TODO 有扫码枪之后
        //'50' => '已打印待备货',
        //'60' => '已备货待发货',

        '60' => '已打印待发货',
        '70' => '配送中',
        '80' => '配送完成',
    );

    const DEALER_WAIT_PAY_OLD = 1;
    const DEALER_WAIT_SEND_OLD = 3;
    const DEALER_SENDING_OLD = 5;
    const DEALER_DONE_OLD = 10;

    // 合伙人订单类型掩码
    const DEALER_CANCEL = 15; //'取消'
    const DEALER_WAIT_PAY = 20; //'待扣款'
    const DEALER_WAIT_CONFIRM = 30; //'已扣款,待确认或加赠品'
    const DEALER_WAIT_PRINT = 40; //'已确认待打印'
    const DEALER_WAIT_PREPARE = 50; //'已打印待备货货'
    const DEALER_WAIT_SEND = 60; //'已备货待发货'
    const DEALER_SENDING = 70; //'配送中(已填送货单号)'
    const DEALER_DONE = 80; //'配送完成'

    // 合伙人订单操作定义
    public static $dealer_order_action = array(
        '1' => '创建订单',
        '15' => '取消订单',
        '21' => '订单扣款',
        '31' => '附加赠品',
        '32' => '确认订单',
        '41' => '打印订单',
        '42' => '再次打印',
        '51' => '仓库备货',
        '61' => '发货填单',
        '62' => '运单修改',
        '71' => '确认收货',
    );

    // 合伙人订单操作掩码
    const DEALER_ACTION_CREATE = 1; // 创建订单
    const DEALER_ACTION_CANCEL = 15; // 取消订单
    const DEALER_ACTION_MINUS = 21; // 确认扣款
    const DEALER_ACTION_ADD_GOODS = 31; // 添加备注(赠品)
    const DEALER_ACTION_CONFIRM = 32; // 确认订单
    const DEALER_ACTION_PRINT = 41; // 打印订单
    const DEALER_ACTION_REPRINT = 42; // 再次打印
    const DEALER_ACTION_PREPARE = 51; // 仓库备货
    const DEALER_ACTION_SEND = 61; // 发货填单
    const DEALER_ACTION_MODIFY_DELIVERY = 62; // 运单修改
    const DEALER_ACTION_DONE = 71; // 确认到货

    // 门店订单状态
    public static $store_progress = array(
        '1' => '未处理',
        '3' => '等待配送',
        '5' => '配送中',
        '10' => '配送完成',
        '15' => '订单取消',
    );

    const STORE_SENDING = 5; //'配送中'
    const STORE_DONE = 10; //'配送完成'

    //BTCP 订单状态
    public static $erp_order_status = array(
        '0' => '暂未处理',   //BTCP不抛送此状态
        '5' => '生成计划',
        '10' => '已打印',
        '15' => '已交接',
    );

    // 发票类型
    public static $invoice_type = array(
        '1' => '电子发票',
        '2' => '增值税普通发票',
    );

    // 配送时间
    public static $deliver_type = array(
        '1' => '送货上门',
    );

    public static $pay_type = array(
        '1' => '上门收款',
        '5' => '微信支付',
        '10' => '支付宝支付',
        '15' => '银联在线',
    );

    /**
     * 所有支付方式列表
     * @var unknown
     */
    public static $pay_type_list = array(
        '1' => '货到付款',
        '2' => '在线支付',
        '3' => '打白条',
    );

    /**
     * 允许的支付方式
     * @var unknown
     */
    public static $allow_pay_type_list = array(
        '1' => '货到付款',
        '2' => '在线支付',
        '3' => '打白条',
    );

    /**
     * 允许显示的支付方式
     * @var unknown
     */
    public static $allow_show_pay_type_list = array(
        '1' => '货到付款',
        '2' => '在线支付',
        '3' => '打白条'
    );


    public static $order_type = array(
        '1' => '总部订单',
        '5' => '合伙人订单'
    );

    // 设置经销商多少箱商品起订
    public static $dealers_trade_order_limit = array(
        'min' => '1',
        'max' => '9999'
    );

    /**
     * 送货审核单状态
     * 限定: 赊账用户
     * @var array
     */
    public static $delivery_status = array(
        '0' => '送货单未传',
        '1' => '送货单待审',
        '5' => '送货单预审完毕',
        '2' => '送货单已审待收款', // 等待回款
        '3' => '送货单驳回',
        '4' => '送货单已审已收款', // 确认已回款
    );

    /**
     * 下单奖励
     * @var array
     */
    public static $reward = array(
        'bulk_bbcoin' => 5
    );

    public static $delegation_type = array(
        '0' => '未知的',
        '1' => '指定合伙人',
        '2' => '指定门店',
    );

    /**
     * 订单Excel导出字段
     * @var array
     */
    public static $order_export_column = array(
        'order_id' => '订单编号',
        'id' => '序号',
        'order_time' => '下单时间',
        'order_status' => '订单状态',
        'order_type' => '订单类型',
        'goods_name' => '商品名称',
        'cup_type' => '杯型',
        'exchange_amount' => '兑换数量',
        'exchange_total_price' => '兑换总价',
        'amount' => '现付数量',
        'price' => '现付总价',
        'total_amount' => '总数量',
        'order_price' => '订单总价',
        'order_pay_price' => '实际支付',
        'order_pay_type' => '支付方式',
        'order_pay_time' => '支付时间',
        'partner_name' => '合伙人姓名',
        'partner_phone' => '合伙人电话',
        'store_id' => '店铺ID',
        'store_name' => '店铺名称',
        'store_addr' => '店铺地址',
        'store_owner' => '掌柜信息',
        'receiver' => '收货人信息',
        'order_delivery_status' => '送货单状态',
    );

    /**
     * 转换旧状态->新状态
     *
     * @param $progress
     * @return int
     */
    public static function dealer_progress_o2n($progress) {

        if ($progress == order_config::DEALER_WAIT_PAY_OLD) {
            return order_config::DEALER_WAIT_PAY;
        } elseif ($progress == order_config::DEALER_WAIT_SEND_OLD) {
            return order_config::DEALER_WAIT_SEND;
        } elseif ($progress == order_config::DEALER_SENDING_OLD) {
            return order_config::DEALER_SENDING;
        } elseif ($progress == order_config::DEALER_DONE_OLD) {
            return order_config::DEALER_DONE;
        }

        return $progress;
    }

    /**
     * 转换旧状态->新旧状态
     * 用于filter兼容
     *
     * @param $progress
     * @return array
     */
    public static function dealer_progress_o2n_filter($progress) {

        $ret = array();

        if ($progress == order_config::DEALER_WAIT_PAY_OLD || $progress == order_config::DEALER_WAIT_PAY) {
            $ret[] = order_config::DEALER_WAIT_PAY_OLD;
            $ret[] = order_config::DEALER_WAIT_PAY;
        } elseif ($progress == order_config::DEALER_WAIT_SEND_OLD) {
            $ret[] = order_config::DEALER_WAIT_SEND_OLD;
            $ret[] = order_config::DEALER_WAIT_CONFIRM;
            $ret[] = order_config::DEALER_WAIT_PRINT;
            $ret[] = order_config::DEALER_WAIT_PREPARE;
            $ret[] = order_config::DEALER_WAIT_SEND;
        } elseif ($progress == order_config::DEALER_WAIT_SEND) {
            $ret[] = order_config::DEALER_WAIT_SEND_OLD;
            $ret[] = order_config::DEALER_WAIT_SEND;
        } elseif ($progress == order_config::DEALER_SENDING_OLD || $progress == order_config::DEALER_SENDING) {
            $ret[] = order_config::DEALER_SENDING_OLD;
            $ret[] = order_config::DEALER_SENDING;
        } elseif ($progress == order_config::DEALER_DONE_OLD || $progress == order_config::DEALER_DONE) {
            $ret[] = order_config::DEALER_DONE_OLD;
            $ret[] = order_config::DEALER_DONE;
        } else {
            $ret[] = $progress;
        }

        return $ret;
    }

    /**
     * 新状态->旧状态
     * 用于app接口兼容
     *
     * @param $progress
     * @return int
     */
    public static function dealer_progress_n2o($progress) {
        if ($progress == order_config::DEALER_WAIT_PAY) {
            return order_config::DEALER_WAIT_PAY_OLD;
        } elseif ($progress > order_config::DEALER_WAIT_PAY && $progress < order_config::DEALER_SENDING) {
            return order_config::DEALER_WAIT_SEND_OLD;
        } elseif ($progress == order_config::DEALER_SENDING) {
            return order_config::DEALER_SENDING_OLD;
        } elseif ($progress == order_config::DEALER_DONE) {
            return order_config::DEALER_DONE_OLD;
        } else {
            return $progress;
        }
    }
}

?>
